< previous page page_251 next page >

Page 251
Using the ListView Control
The ListView control is similar to the ListBox but is enhanced in a number of ways. The ListView control can display information in one of a variety of modes: icon lists that are arranged from left to right, a columnar list, or a "report" view. These options correspond to the options in the Windows Explorer's View menu (Large Icons, Small Icons, List, or Details). After the items are stored in the ListItems collection, you can simply set the View property to switch to any of the modes you want.
The report-style list is special because it shows more information than the other modes. When using the Windows Explorer, you may have noticed that the Details option displays more information than just the filename. In this case, the filename is the main item, and the size, type, and date modified are "sub-items" associated with each filename.
In your programs, you control sub-items with the SubItems property, which is an array of strings associated with each item in the list. A ColumnHeaders collection supplies the headings at the top of the report.
Recall from earlier in this chapter that the ImageList control supplies pictures for other Common controls. The ListView control can use up to three ImageLists because it can display both large and small icons, as well as pictures in the column headers. You can set these ImageLists in the Property Pages dialog box or in code, as follows:
Set lViewMain.Icons = ImageList1
Set lViewMain.SmallIcons = ImageList2
Set lViewMain.ColumnHeaderIcons = ImageList3
The ability to add Column Header images is a new feature in the Common controls included with Visual Basic 6.0. square.gif
If you don't set the SmallIcons, Icons, and ColumnHeaderIcons properties of the ListView control, no images will appear. Also, using the smaller ImageList dimension (16×16) is a good idea when you are filling the image list that you plan to use for small icons.
Recall that the ListBox control's items are stored in an array. All the items in a ListView control are in a collection called ListItems, and each item has several properties, including an index to the icon images and a caption. As with most collections, the ListItems collection has an Add method, which is defined as follows:
listview1.ListItems.Add ,"mykey","My Item",1,1
You will learn more details about each parameter of the ListView's Add method as you build the sample project.
Starting the Sample Project
The sample program will display a list of baseball teams and their win/loss statistics. To begin the project, follow these steps:
1. Start a new Standard EXE project in Visual Basic.
2. As described earlier in the chapter, add the Microsoft Windows Common Controls 6.0 to your Toolbox.

 
< previous page page_251 next page >